package com.example.hanchen.yongkanggy.home.base;

import android.app.Application;

import androidx.annotation.NonNull;

import com.example.hanchen.yongkanggy.home.interfaces.OnRequestListener;

public class BaseRequestStateViewModel extends BaseViewModel {

    /**
     * 请求状态
     */
    protected OnRequestListener mRequestListener;

    public BaseRequestStateViewModel(@NonNull Application application) {
        super(application);
    }

    public void setRequestListener(OnRequestListener requestListener) {
        mRequestListener = requestListener;
    }

    protected void onLoading() {
        if (mRequestListener == null) {
            return;
        }
        mRequestListener.onLoading();
    }
    protected void onError(String error){
        if (mRequestListener == null) {
            return;
        }
        mRequestListener.onError(-1,error);
    }
    protected void onError(int code,String error){
        if (mRequestListener == null) {
            return;
        }
        mRequestListener.onError(code,error);
    }
    protected void onSuccess(Object data){
        if (mRequestListener == null) {
            return;
        }
        mRequestListener.onSuccess(data);
    }
}


